package cn.com.api.mapper;

import java.util.List;
import java.util.Map;


import org.apache.ibatis.annotations.*;

import cn.com.api.entity.ApiU_match;
import cn.com.api.mapper.base.U_matchMapperBase;

//DAO
public interface ApiU_matchMapper extends U_matchMapperBase {

	// 新增对象后返回记录ID
	public int U_matchInsertion(ApiU_match u_match);

	// 根据条件查询赛事列表
	public List<ApiU_match> findU_matchs_condition(Map<String, Object> param);
	
	//查询我的赛事列表
	public List<ApiU_match> findU_matchs_main(Map<String, Object> param);
	
	public List<ApiU_match> findU_matchs_award(Map<String, Object> param);
	
	public List<ApiU_match> findU_matchs_vote(Map<String, Object> param);

	// 根据条件查询列表
	public List<ApiU_match> findU_matchs_detail_condition(Map<String, Object> param);

	// 修改
	@Update("UPDATE U_MATCH SET MATCH_NAME = #{match_name}, JOIN_COUNT = #{join_count}, ENT_ID = #{ent_id}, AMOUNT = #{amount}, MATCH_INTRODUCE = #{match_introduce}, MATCH_RULES = #{match_rules}, THUMBNAIL = #{thumbnail}, THUMBNAIL_H5 = #{thumbnail_h5}, PSTART_TIME = #{pstart_time}, PEND_TIME = #{pend_time}, VSTART_TIME = #{vstart_time}, VEND_TIME = #{vend_time}, RESULT_TIME = #{result_time}, COUNTER_FEE = #{counter_fee}, BONUS_AMOUNT = #{bonus_amount}, STATUS = #{status}, REJECT_REASON = #{reject_reason}, IS_PAY = #{is_pay}, WIN_AMOUNT = #{win_amount}, GUESS_AMOUNT = #{guess_amount}, IS_NEED_VEDIO = #{is_need_vedio}, EXT1 = #{ext1}, EXT2 = #{ext2}, EXT3 = #{ext3}, EXT4 = #{ext4}, EXT5 = #{ext5},"
			+ " AUDIT_BY = #{audit_by}," + " MATCH_CATE = #{match_cate}," + " AUDIT_TIME = #{audit_time}"
			+ " WHERE MATCH_ID = #{match_id}")
	public int updateU_match_info(ApiU_match u_match);

	public List<ApiU_match> findU_api_matchs_join(Map<String, Object> params);

	public List<ApiU_match> findU_api_matchs_nominate(Map<String, Object> params);

	public List<ApiU_match> findU_matchsByMatchName(Map<String, Object> params);

	public List<ApiU_match> findU_api_matchs_vote(Map<String, Object> params);

	@Select(" select count(*) from u_match_works where user_id = #{user_id} and match_id = #{match_id} ")
	public int findU_enroll_status(Map<String, Object> params);

	@Select(" select count(*) from ( select * from u_match_vote where  user_id = #{user_id} )a left join u_match_works w"
			+ " on w.works_id = a.match_works_id" + " where w.match_id =  #{match_id} ")
	public int findU_vote_status(Map<String, Object> params);

	@Select(" select count(v.vote_id) as vote_num from u_match_vote v left join u_match_works w"
			+ " on v.match_works_id = w.works_id where w.match_id = #{match_id}")
	public int findU_api_matchs_votenum(String match_id);

	@Select("select count(v.works_id)as works_num from u_match_works v where v.match_id = #{match_id}")
	public int findU_api_matchs_worksnum(String match_id);

	public void updateMatchAward(List<ApiU_match> matchs);
	
	public List<ApiU_match> findU_api_matchs_mywin(Map<String, Object> params);

	public ApiU_match findMatchInfo(Integer match);
}
